import React, { Component } from 'react'
import { BasicPagination, compareNum, TableCustomize, openSuccessModal, openModalMessage } from '../../../components/TableCustomize';
export default class MonthCommand extends Component {
    state = {
        some: null,
        selectedRows: [],
        selectedRowKeys: [],
    };
    fetch = (pageNum = 1, pageSize = 10) => {
        console.log(pageNum, pageSize);
        let paging1 = { pageNum: pageNum, pageSize: pageSize }
        this.props.paging1(paging1)
    }
    render() {
        const { dataSource } = this.props.search1[0]
        const { pageNum, pageSize, total } = this.props.search1[1]
        const { selectedRowKeys } = this.state;
        const rowSelection = {
            type: 'checkbox',
            selectedRowKeys: selectedRowKeys,
            onChange: (selectedRowKeys, selectedRows) => {
                let some = [...selectedRows].length
                let rowSelections = [some, selectedRows]
                this.props.rowSelection(rowSelections)
                this.setState({
                    some: some,
                    selectedRows: selectedRows,
                    selectedRowKeys: selectedRowKeys
                }, () => {
                    // console.log('选中个数', this.state.some, '选中详细数据', this.state.selectedRows);
                })
            },
            // 固定在左侧
            // fixed: true
        }
        const columns = [
            {
                title: '序号',
                dataIndex: 'number',
                width: 50,
                // ellipsis: true,
                // fixed: 'left',
                render: (text, record, index) =>
                    <div>
                        {index + 1}
                    </div>
            },
            {
                title: '变更类型',
                dataIndex: 'changeType',
                sorter: (a, b) => compareNum(a.changeType, b.changeType),
                // ellipsis: true,
                width: 120,
            },
            {
                title: '批号',
                width: 120,
                dataIndex: 'batchNo',
                sorter: (a, b) => compareNum(a.batchNo, b.batchNo),
                // ellipsis: true,
            },
            {
                title: '装配部门',
                width: 110,
                dataIndex: 'assemblyDept',
                // ellipsis: true,
            },
            {
                title: '变更内容',
                width: 220,
                dataIndex: 'changeMessage',
                // ellipsis: true,
            },
            {
                title: '变更日期',
                width: 150,
                dataIndex: 'changeTime',
                sorter: (a, b) => compareNum(a.changeTime, b.changeTime),
                // ellipsis: true,
            },
            {
                title: '变更人',
                dataIndex: 'user',
                // ellipsis: true,
            },
        ]
        return (
            <div>
                <TableCustomize
                    rowSelection={rowSelection}
                    columns={columns}
                    rowKey={(record) => record.id}
                    dataSource={dataSource}
                    pagination={false}
                    allowDrafting={true}
                    scroll={{ x: true, y: 500 }}
                    rowClassName={(record, index) => {
                        return (['editable-row', index % 2 === 0 ? 'editable-row' : 'editable-row12'])
                    }}
                />
                <BasicPagination pageNum={pageNum} pageSize={pageSize} total={total} loadData={this.fetch} />
            </div>
        )
    }
} 